OCLps Example


In this example, we look at a small model that stores articles with comments made by users. There may be a lot of comments on the article and below is a description of how to efficiently find "my" comments. "My" refers to the logged-in user.

There are different approaches to improving the performance of retrieving the comment section for an article. These include selecting the article based on the self and the first comment, using the PSEval value to calculate the number of liked comments, and combining PSEval with OCL.

One of these methods is through the use of PSEvalValue. PSEvalValue provides a way to select and manipulate data in the database without loading it into memory.

To illustrate how PSEval works, let's consider a small model that involves three tables: Article, SysUser, and Comment.

OCLps Example Image.png

The link role allows for navigation from SysUser to Comment and vice versa. This model assumes that a single SysUser won't have excessive comments.

Suppose we want to display the number of likes that an article has received. One way to do this is to load every comment object into memory, filter out the ones that have a "like" and then count how many there are. However, this would be inefficient for articles with several comments. A better way is to use PSEvalValue to select only the comments that have a "like" and count them without loading them into memory.

However, using PSEvalValue has its limitations. If a user likes or unlikes a comment, the "like" count in the user interface will not update because nothing is triggering a re-evaluation of the data. One way to work around this is to use PSEval to get all the comments for an article but only the ones that have a "like" on them. This method still loads objects, but it only loads the ones with a "like" which can improve performance. PSEval can make querying large datasets much faster and more efficient.

Learn More in This Video

This page was edited 153 days ago on 06/17/2024. What links here